package com.chenyi.algorithm.sort;

import java.util.Arrays;

/**
 * @author chenyi
 */
public class SelectSorting {

    public static void main(String[] args) {
        int[] array = {8, 1, 22, 5, 123, 3};

        sort(array);

        System.out.println(Arrays.toString(array));

    }

    public static int[] sort(int[] array) {
        for (int i = 0; i < array.length; i++) {
            int minIndex = i;
            for (int j = i + 1; j < array.length; j++) {
                if (array[minIndex] > array[j]) {
                    minIndex = j;
                }
            }

            if (minIndex != i) {
                int min = array[i];
                array[i] = array[minIndex];
                array[minIndex] = min;
            }
        }
        return array;
    }

}
